<?php
defined('_XR_EXEC') or die();
/**
 * Debug调试类
 * 
 * by zhoupeng 2011-7-8  
 * zhoupeng10@gmail.com
 *
 */
class debug{
	# 实例化自己
	public static function singleton()
	{
		static $instances;
		if (!isset ($instances))
		{
			$instances = new debug();
		}
		return $instances;
	}
	/**
	* 显示变量调试，并终止程序
	* 
	* 
	*/
  public static function show(){
		$args = func_get_args();
		echo '---------------------debug begin---------------------<pre>';
		foreach ($args as $value) {
			if(is_null($value)){
				echo '[is_null]';
			}elseif(is_bool($value) || empty($value)){
				var_dump($value);
			}else{
				print_r($value);
			}
			echo '<br>';
		}
		$trace=debug_backtrace();
		$next = array_merge(
			array(
				'line'		=> '??',
				'file'		=> '[internal]',
				'class'		=> null,
				'function'	=> '[main]'
			),
			$trace[0]
		); 
		echo '---------------------debug end---------------------';
		echo '<div style="color:red;">'.$next['file'].' line:'.$next['line'].'</div>';
		if(in_array('debug',$args)){
			print_r($trace);
		}
		$end_time = array_sum(explode(' ', microtime()));
		$var=sprintf('%.6f',$end_time-XR_START_TIME);
		echo '<div style="color:green;">Parse Time:'.$var.'s</div>';
		
		echo '<div style="color:green;">Memory:'.number_format((memory_get_usage()/1024/1024),4).' M</div>';
			 
		echo '</pre>';
		exit();		
	}
	
	/**
	* 记录日志。。。
	* 
	* 
	*/
	public static function Logs(){
		
	}
	
}
?>